//
//  InputViewController.m
//  WangLottery
//
//  Created by 黄修勇 on 12-5-7.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "InputViewController.h"

@interface InputViewController ()

@end

@implementation InputViewController


@synthesize inputTextFailed=_inputTextFailed;
@synthesize delegate=_delegate;

-(void)dealloc{

    [_inputTextFailed release];
    _delegate=nil;
    [super dealloc];
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self changeBackNavItem];
    [backItemButton addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
    
    _inputTextFailed.frame=CGRectMake(_inputTextFailed.frame.origin.x, _inputTextFailed.frame.origin.y, _inputTextFailed.frame.size.width, 42.0f);
    /*
    UIButton *doneBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    doneBtn.frame=CGRectMake(0.0f, 7.0f, 60.0f, 32.0f);
    [doneBtn setBackgroundImage:[UIImage imageNamed:@"bit_normal.png"] forState:UIControlStateNormal];
    doneBtn.titleLabel.font=[UIFont boldSystemFontOfSize:14.0f];
    [doneBtn setTitle:@"确定" forState:UIControlStateNormal];
    [doneBtn addTarget:self action:@selector(doneBtn:) forControlEvents:UIControlEventTouchUpInside];
    [doneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [doneBtn setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem *item=[[UIBarButtonItem alloc]initWithCustomView:doneBtn];
    self.navigationItem.rightBarButtonItem=item;
    [item release];
    */
    // Do any additional setup after loading the view from its nib.
}

-(void)cancel:(UIButton *)btn{

    [self.navigationController popViewControllerAnimated:YES];
    if (_delegate&&[_delegate respondsToSelector:@selector(cancelDissViewController:)]) {
        [_delegate cancelDissViewController:self];
    }
}

-(IBAction)doneBtn:(UIButton *)btn{

    if (_delegate&&[_delegate respondsToSelector:@selector(checkEndInputText:inputViewController:)]) {
        BOOL isOk=[_delegate checkEndInputText:_inputTextFailed.text inputViewController:self];
        if (isOk==NO)
            return;
    }
    if(_delegate&&[_delegate respondsToSelector:@selector(doneDissViewController:userInputText:)]){
        
        [_delegate doneDissViewController:self userInputText:_inputTextFailed.text];
    }
    [self.navigationController popViewControllerAnimated:YES];
}


-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];
    
    [_inputTextFailed becomeFirstResponder];
    
}

-(void)viewWillDisappear:(BOOL)animated{

    [super viewWillDisappear:animated];
    
    [_inputTextFailed resignFirstResponder];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
